﻿#pragma once

#include "Math/Color.h"
#include "Math/Rect.h"
#include <vulkan/vulkan.hpp>
#include "Render/Texture/RenderTexture2D.h"
#include "Render/Scene/CameraParameters.h"
#include "Render/Scene/PreRenderScene.h"
#include "Render/AntiAlisingMethod.h"
#include "Render/ForegroundMesh/PreRenderForegroundMeshInstance.h"
#include "Render/Widget/CharUniformBufferData.h"

class CPreRenderTexture2D;
class CPreRenderPixelObjectGroup;

struct SRenderCommandBuffers
{
    void Clear()
    {
        RectWidgetRenderPassCommandBuffers.Clear();
        ImageWidgetRenderPassCommandBuffers.Clear();
        TextImageWidgetRenderPassCommandBuffers.Clear();
        SceneCommandBuffers.Clear();
        ForegroundCommandBuffers.Clear();
        CanvasWidgetRenderPassCommandBuffers.Clear();
    }

    bool Empty()
    {
        return 
            RectWidgetRenderPassCommandBuffers.Empty()
            && ImageWidgetRenderPassCommandBuffers.Empty()
            && TextImageWidgetRenderPassCommandBuffers.Empty()
            && SceneCommandBuffers.Empty()
            && ForegroundCommandBuffers.Empty()
            && CanvasWidgetRenderPassCommandBuffers.Empty()
            ;
    }

    TVector<vk::CommandBuffer> RectWidgetRenderPassCommandBuffers;

    TVector<vk::CommandBuffer> ImageWidgetRenderPassCommandBuffers;

    TVector<vk::CommandBuffer> TextImageWidgetRenderPassCommandBuffers;

    TVector<vk::CommandBuffer> CanvasWidgetRenderPassCommandBuffers;

    TVector<vk::CommandBuffer> SceneCommandBuffers;

    //command buffer render axis in editor
    TVector<vk::CommandBuffer> ForegroundCommandBuffers;
};


struct SPreRenderWidgetBase
{
    //深度
    float Depth=0.0f;

    //视口
    vk::Viewport Viewport;

    //裁剪,最少一个裁剪矩形，否则会使用上一个元素的裁剪矩形
    //单位是像素
    vk::Rect2D Scissor;
};

//渲染矩形需要的数据
//填满整个视口
struct SPreRenderRectWidget : public SPreRenderWidgetBase
{
    SColor Color;
};

struct SPreRenderCircleWidget : public SPreRenderWidgetBase
{
    SColor Color;

    //圆心,单位是像素，在窗口上的绝对位置
    SVec2 Center;

    //半径,单位是像素
    float Radius;
};

struct SPreRenderRingWidget : public SPreRenderWidgetBase
{
    SColor Color;

    //圆心,单位是像素
    SVec2 Center;

    //外圆半径,单位是像素
    float Radius;

    //环的宽度,单位是像素
    float Width;
};


struct SPreRenderImageWidget : public SPreRenderWidgetBase
{
    //左上角的uv坐标
    SVec2 LeftTopUV;

    //右下角的uv坐标,如果图片需要重复
    //则右下角的uv坐标应该大于1
    SVec2 RightBottomUV;

    //图片资源
    std::shared_ptr<CPreRenderTexture2D> Image;

    SColor TintColor;
};

//一个文本控件就是一批文字图片
//不同的控件不能合批,因为裁剪矩形不同
struct SPreRenderTextWidget : public SPreRenderWidgetBase
{
    //存放所有的文字图片
    std::shared_ptr<CPreRenderTexture2D> TextImage;

    //每个字符的数据
    TVector<SCharUniformBufferData> CharData;

};

//静态文本控件，只有一张图片
struct SPreRenderStaticTextWidget : public SPreRenderWidgetBase
{
    //文字图片
    std::shared_ptr<CPreRenderTexture2D> TextImage;

    //每个字符的数据
    TVector<SStaticCharUniformBufferData> CharData;

    SColor TextColor;

};

struct SPreRenderTriangleWidget : public SPreRenderWidgetBase
{
    SColor Color;

    //在控件上顺时针的三个点
    SVec2 P0;
    SVec2 P1;
    SVec2 P2;
};

struct SPreRenderLineWidget : public SPreRenderWidgetBase
{
    SColor Color;

    //在控件上的两个点
    SVec2 Start;
    SVec2 End;

    //线宽
    float Width=1.0f;
};

struct SPreRenderViewportWidget  : public SPreRenderWidgetBase
{
    TVector<CPreRenderScene> Scenes;

    TVector<SPreRenderForegroundMeshInstance> ForegroundMeshInstances;

    //相机参数
    SRenderCameraParameters CameraParameters;
    
    //抗锯齿
    EAntiAliasingMethod AntiAliasingMethod=EAntiAliasingMethod::None;

    //像素对象
    std::shared_ptr<CPreRenderPixelObjectGroup> PixelObjects;
};


struct SPreRenderWidgets
{
    TVector<SPreRenderRectWidget> RectWidgets;

    TVector<SPreRenderCircleWidget> CircleWidgets;

    TVector<SPreRenderRingWidget> RingWidgets;

    TVector<SPreRenderImageWidget> ImageWidgets;

    TVector<SPreRenderTextWidget> TextWidgets;

    TVector<SPreRenderStaticTextWidget> StaticTextWidgets;

    TVector<SPreRenderLineWidget> LineWidgets;

    TVector<SPreRenderTriangleWidget> TriangleWidgets;

    TVector<SPreRenderViewportWidget> ViewportWidgets;
};

